let app = getApp()
Component({ 
    properties: {
         pagetitle:String
      },
      data:{
        applyDistribution: "",
        tabArr: [ {
          icon: "../../../static/image/team.png",
          name: "我的团队"
      }, {
          icon: "../../../static/image/mineCustomer.png",
          name: "我的客户",
          url: ""
      }, {
          icon: "../../../static/image/commission.png",
          name: "佣金明细",
          url: ""
      }, {
          icon: "../../../static/image/orderDetail.png",
          name: "订单明细",
          url: ""
      }, {
          icon: "../../../static/image/cashWithdrawalDetail.png",
          name: "提现明细",
          url: ""
      }, {
          icon: "../../../static/image/mineCard.png",
          name: "我的账户",
          url: ""
      }, {
          icon: "../../../static/image/extension.png",
          name: "推广全店",
          url: ""
      }, {
          icon: "../../../static/image/invitationCustomer.png",
          name: "邀请客户",
          url: ""
      } ]
      },
    lifetimes: {
        attached: function () {
          this.setData({
            getGlobalColor:app.globalData.globalColor,
            pageHeight:wx.getSystemInfoSync().windowHeight-80
          })
          var that=this
          wx.request({
              url: app.globalData.siteroot,
              data: {
                do:'Distribution_getDistributionSetting',
                user_id:wx.getStorageSync('user_id'),
              },
              success: function(res) {
                  that.setData({
                    distributionSetting:res.data.data
                  }) 
                  wx.setStorageSync('distribution',res.data.data);
              }
            })
            wx.request({
              url: app.globalData.siteroot,
              data: {
                do:'Distribution_getDistributionUser',
                user_id:wx.getStorageSync('user_id'),
              },
              success: function(res) {
                  if(res.data.data.length==0)
                  {
                    that.setData({
                      applyDistribution:'true'
                    })
                  }
                  else
                  {
                    if(res.data.data.status==0)
                    {
                      that.setData({
                        applyDistribution:'true'
                      })
                    }else{
                      that.setData({
                        applyDistribution:'false'
                      })
                    }
                    that.setData({
                      distributionInfo:res.data.data
                    })
                    wx.setStorageSync('distributionInfo',res.data.data);
                    wx.setStorageSync('distribution_id',res.data.data.id);
                  }
              }
            })
       }
      },
    methods: {
      go_cash_withdrawal:function(){
        wx.navigateTo({
          url: '/yb_shopv2/native/all/index?type=page_applyCw',
        }) 
      },
      apply:function(){
        wx.navigateTo({
          url: '/yb_shopv2/native/all/index?type=page_apply_distribution',
        })
      },
      tabinfo:function(e){
        var key=e.currentTarget.dataset.key
        if(key==0||key==1||key==2||key==4||key==5){
          wx.navigateTo({
            url: '/yb_shopv2/native/all/index?type=page_IntegralDistributionList&layer_num=1&index='+key+'&distribution_id='+wx.getStorageSync('distribution_id')
          })
        }else if(key==3){
          wx.navigateTo({
            url: '/yb_shopv2/native/all/index?type=distribution_order_detail'
          })
        }else if(key==6){
          wx.navigateTo({
            url: '../../pages/distribution/child/ewmPoster?type=extension'
          })
        }else if(key==7){
          wx.navigateTo({
            url: '../../pages/distribution/child/ewmPoster?type=invitation'
          })
        }
      }
    }
});
